function gen_func1<T>(arg:T):T[] {
	const str = []
	str.push(arg + '!')
	return str
}

let resultsd =  gen_func1<string>('Hello world');
console.log(resultsd)

class Qyeye<T>{
	private data:T[] = [];
	push = (item: T) => this.data.push(item);
	pop = () : T | undefined => this.data.shift();
}

const queue = new Qyeye<number>();
queue.push(0);

//二种
let gen_func2:<T>(arg:T) => T = function(arg) {
	return arg;
}

gen_func2('Hello world')
// 第二种调用方式可省略类型参数，因为编译器会根据传入参数来自动识别对应的类型。

function any_func<T>(arg:Array<T>): Array<T> {
	console.log(arg.length)
	return arg
}

function reverse<T>(items:T[]):T[]{
	const toreturn = [];
	for(let i =items.length - 1 ; i >= 0; i--) {
		toreturn.push(items[i]);
	}
	return toreturn;
}

const sample = [1 , 2 , 3];
let reversed = reverse(sample);
// let reversed = reverse<number>(sample);
// console.log(reversed)

// reversed[0] = '1'; // Error
// reversed = ['1', '2']; // Error

reversed[0] = 1; // ok
reversed = [1, 2]; // ok
//传入的数组里面是number 类型  所以输出赋值也要是number
